home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_04 / 2n04026a < prev    next >
Text File  |  1991-02-23  |  2KB  |  67 lines

  1. {Listing1.asm - delay.asm}
  2.  
  3.  
  4.  
  5. ; This file contains the routines to perform a 10ms delay 
  6. ; using the system timer.
  7. ;
  8.      .MODEL  SMALL, C
  9.  
  10.      .DATA
  11. ;
  12. ; Video segment and offset used in delay logic
  13. ;
  14. video   LABEL   DWORD
  15. vid_seg DW   0
  16. vid_off DW   0
  17.  
  18.      .CODE
  19.  
  20.      PUBLIC  fdcDelay, calibrateDelay
  21. ;
  22. ; Perform a delay to allow the FDC Controller to catch up.  
  23. ; This process works by waiting for the video memory, 
  24. ; which is located on the system bus
  25. ;
  26. fdcDelay PROC
  27.      push   es
  28.      les  bx, video
  29.      mov  al, es:[bx]
  30.      mov  es:[bx], al
  31.      pop  es
  32.      ret
  33. fdcDelay ENDP
  34.  
  35. ;
  36. ; Determine the address to use for the delay operation.  
  37. ; For color text modes, use the second video page in 
  38. ; order to avoid creating snow on a CGA.
  39. ;
  40. calibrateDelay PROC
  41.    push   bp
  42.    mov  ah, 0fh   ; get curent video mode
  43.    int  10h
  44.    cmp  al, 7     ; monochrome display?
  45.    je   mono      ;  yes, set the address accordingly
  46.    mov  vid_seg, 0B800h ; Color address == 
  47.                         ; 0xB800:((page+1)%2)*4000
  48.    xor  ax, ax    ; AX == offset
  49.    mov  bl, bh    ; mov page number to BL
  50.    inc  bl
  51.    and  bl, 01h      ; use odd/even pages due to 
  52.                      ; alternate text modes
  53.    jz   page0
  54.    mov  ax, 4000     ; use page 1
  55. page0:
  56.    mov  vid_off, ax
  57.    jmp  SHORT done
  58. mono:
  59.    mov  vid_off, 0   ; Monochrome address == 0xB000:0000
  60.    mov  vid_seg, 0B000h
  61. done:
  62.    pop  bp
  63.    ret
  64. calibrateDelay ENDP
  65.  
  66.    END
  67.